package com.shumei.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.shumei.dao.mapper.EqMapper;
import com.shumei.dao.pojo.Application;
import com.shumei.dao.pojo.Eq;
import com.shumei.service.EqService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EqServiceImpl implements EqService {
    @Autowired
    EqMapper eqMapper;
    @Override
    public void insertEq(Eq eq) {
       Eq eq1= selectByname(eq.getEqName());
        if (eq1!=null) {
            System.out.println("公司注册信息已存在");
        }
        else {
            int i = eqMapper.insert(eq);
            if (i > 0) {
                System.out.println("公司信息录入成功");

            } else {
                System.out.println("公司信息录入失败");

            }
        }
    }

    @Override
    public Eq selectByname(String eqname) {
        QueryWrapper<Eq> wrapper=new QueryWrapper<Eq>();
        wrapper.eq("eq_name",eqname);
        Eq eq =eqMapper.selectOne(wrapper);
        return eq;
    }

    @Override
    public void deleteeq(int id){
        int i = eqMapper.deleteById(id);
        if (i>0) {
            System.out.println("删除成功");
        }else{
            System.out.println("删除失败");
        }
    }

    @Override
    public void updateEq(Eq eq) {
        QueryWrapper<Eq> wrapper=new QueryWrapper<Eq>();
        wrapper.eq("id",eq.getId());

        if (eqMapper.update(eq,wrapper)>0){
            System.out.println("修改成功");
        }
        else {
            System.out.println("修改失败");
        }
    }

    @Override
    public void selectallEq() {

        List<Eq> eqs= eqMapper.selectList(null);
        for (Eq eq : eqs) {
            System.out.println(eq);
        }

    }
}
